package com.efast.dmom.mes.datahandlers.entity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.dmom.mes.bean.PartGroup;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.dao.entity.PartGroupDao;
import com.efast.dmom.mes.datahandlers.base.PartRelateDataHandler;
import com.efast.dmom.mes.entity.PartGroupEntity;
import com.efast.dmom.mes.util.SpringWebUtils;
import com.efast.dmom.mes.util.TimeUtil;

@Component
public class PartGroupDataHandler extends PartRelateDataHandler<PartGroup>{
	
	@Autowired
	private PartGroupDao partGroupDao;
	
	@Override
	public ResultBean save(PartGroup obj) {
		ResultBean resultBean = new ResultBean(true,' ');
		obj.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
		obj.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setCreator(SpringWebUtils.getRequestUser());
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setCreationPid(DataHandlerUtils.getDmomPid());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowStatus(1);
		obj.getInnerData().setRowTrxId(1);
		partGroupDao.save(obj.getInnerData());
		resultBean.setSuccess(true);
		resultBean.setMessage("保存成功！");
		return resultBean;
	}
	@Override
	public ResultBean update(PartGroup obj) {
		ResultBean resultBean = new ResultBean();
		
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowTrxId(1);
		partGroupDao.update(obj.getInnerData());
		resultBean.setSuccess(true);
		resultBean.setMessage("修改成功！");
		return resultBean;
	}
	
	@Override
	public ResultBean delete(PartGroup obj) {
		ResultBean resultBean = new ResultBean(true,' ');
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowTrxId(1);		
		partGroupDao.delete(obj.getInnerData());
		resultBean.setSuccess(true);
		resultBean.setMessage("删除成功！");
		return resultBean;
	}

	public PartGroup getById(long id) {
		PartGroup partGroup = new PartGroup();
		PartGroupEntity partGroupEntity = partGroupDao.getById(id);
		if (partGroupEntity != null) {
		  partGroup.setInnerData(partGroupEntity);
		}
		return partGroup;
	}

	public PartGroup getByName(String name) {
		PartGroup partGroup = new PartGroup();
		PartGroupEntity partGroupEntity = partGroupDao.getByName(name);
		if (partGroupEntity != null) {
			  partGroup.setInnerData(partGroupEntity);
		}
		return partGroup;
	}

	public PartGroup getByPartGroupCode(String partGroupCode) {
		PartGroup partGroup = new PartGroup();
		PartGroupEntity partGroupEntity = partGroupDao.getByCode(partGroupCode);
		if (partGroupEntity != null) {
			  partGroup.setInnerData(partGroupEntity);
		}
		return partGroup;
	}

	@Override
	public ResultBean saveBatch(List<PartGroup> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean updateBatch(List<PartGroup> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean deleteBatch(List<PartGroup> obj) {
		// TODO Auto-generated method stub
		return null;
	}

}
